Telegram Group & Telegram Channel
Разница между __str__ и __repr__

Оба магических метода __str__ и __repr__ используются для получения строкового представления объекта. Давайте разберемся, в чем же собственно разница между ними.

Метод __str__ используется для создания вывода для конечного пользователя, а __repr__ в основном используется для отладки и разработки. Другими словами, цель __repr__ – быть однозначным, а __str__ – читабельным.

Функция print() и встроенная функция str() используют метод __str__ для отображения строкового представления объекта, а вот встроенная функция repr() использует для этого метод __repr__.

#классы #str #repr



tg-me.com/python_academy/847
Create:
Last Update:

Разница между __str__ и __repr__

Оба магических метода __str__ и __repr__ используются для получения строкового представления объекта. Давайте разберемся, в чем же собственно разница между ними.

Метод __str__ используется для создания вывода для конечного пользователя, а __repr__ в основном используется для отладки и разработки. Другими словами, цель __repr__ – быть однозначным, а __str__ – читабельным.

Функция print() и встроенная функция str() используют метод __str__ для отображения строкового представления объекта, а вот встроенная функция repr() использует для этого метод __repr__.

#классы #str #repr

BY Python Academy




Share with your friend now:
tg-me.com/python_academy/847

View MORE
Open in Telegram


Python Academy Telegram | DID YOU KNOW?

Date: |

How Does Bitcoin Work?

Bitcoin is built on a distributed digital record called a blockchain. As the name implies, blockchain is a linked body of data, made up of units called blocks that contain information about each and every transaction, including date and time, total value, buyer and seller, and a unique identifying code for each exchange. Entries are strung together in chronological order, creating a digital chain of blocks. “Once a block is added to the blockchain, it becomes accessible to anyone who wishes to view it, acting as a public ledger of cryptocurrency transactions,” says Stacey Harris, consultant for Pelicoin, a network of cryptocurrency ATMs. Blockchain is decentralized, which means it’s not controlled by any one organization. “It’s like a Google Doc that anyone can work on,” says Buchi Okoro, CEO and co-founder of African cryptocurrency exchange Quidax. “Nobody owns it, but anyone who has a link can contribute to it. And as different people update it, your copy also gets updated.”

If riding a bucking bronco is your idea of fun, you’re going to love what the stock market has in store. Consider this past week’s ride a preview.The week’s action didn’t look like much, if you didn’t know better. The Dow Jones Industrial Average rose 213.12 points or 0.6%, while the S&P 500 advanced 0.5%, and the Nasdaq Composite ended little changed.

Python Academy from in


Telegram Python Academy
FROM USA